package cn.wuqingna.legendgem.gui.gemmanager

import cn.wuqingna.legendgem.gui.Gui
import org.bukkit.entity.Player
import taboolib.library.xseries.XMaterial
import taboolib.module.nms.ItemTag
import taboolib.module.ui.ClickEvent
import taboolib.platform.util.takeItem

object LuckManager {
    fun luck(event: ClickEvent, gui: Gui){
        clear(event.clicker, gui)

    }
    fun clear(player: Player, gui: Gui){
        gui.typeSlot["LUCK"]!!.forEach {
            gui.inventory!!.setItem(it, XMaterial.AIR.parseItem())
        }
        gui.luck = 0
        player.inventory.takeItem { it.isSimilar(gui.luckItem) }

    }
    // 点击背包操作
    fun clickInventory(event: ClickEvent, gui: Gui, tag: ItemTag){
        val luck = tag.getDeep("legendGem.gem-luck")
        if (luck != null){
            val item  = event.clickEvent().currentItem
            gui.typeSlot["LUCK"]!!.forEach {
                gui.inventory!!.setItem(it, item)
            }

            gui.luck += luck.asInt()
            gui.luckItem = item
        }


    }

}